// import com.alibaba.druid.support.logging.Log;
// import com.alibaba.druid.support.logging.LogFactory;

// import java.util.Calendar;
// import java.util.TimeZone;

#pragma once
#include <string>
#include <vector>
#include <time.h>
#include "common_ptr.h"

namespace StringUtils
{
  // public:
  // final Log LOG = LogFactory.getLog(StringUtils.class);

  // StringUtils();

  /**
   * Example: subString("12345","1","4")=23
   *
   * @param src
   * @param start
   * @param to
   * @return
   */
  int subStringToInteger(string_ptr src, string_ptr start, string_ptr to);

  /**
   * Example: subString("abcd","a","c")="b"
   *
   * @param src
   * @param start NULL while start from index=0
   * @param to    NULL while to index=src.length
   * @return
   */
  string_ptr subString(string_ptr src, string_ptr start, string_ptr to);

  /**
   * Example: subString("abcdc","a","c",true)="bcd"
   *
   * @param src
   * @param start  NULL while start from index=0
   * @param to     NULL while to index=src.length
   * @param toLast true while to index=src.lastIndexOf(to)
   * @return
   */
  string_ptr subString(string_ptr src, string_ptr start, string_ptr to, bool toLast);

  /**
   * @param in
   * @return
   */
  int stringToInteger(string_ptr in);

  bool equals(string_ptr a, string_ptr b);

  bool equalsIgnoreCase(string_ptr a, string_ptr b);
  bool equalsIgnoreCase(std::wstring a, std::wstring b);
  bool iequals(string_ptr a, string_ptr b);
  bool iequals(std::wstring a, std::wstring b);
  bool iequals(std::string a, std::string b);
  // bool isEmpty(CharSequence* value) ;

  int lowerHashCode(string_ptr text);

  bool isNumber(string_ptr str);
  bool isNumber(char *chars);

  string_ptr formatDateTime19(long millis, time_t timeZone);

  string_ptr removeNameQuotes(string_ptr s);
  // string_ptr removeNameQuotes(string_ptr s);

  bool endWith(const string_ptr str, const string_ptr tail);
  bool startWith(const string_ptr str, const string_ptr head, std::size_t pos = 0);

  void split(const string_ptr strtem, const char a, std::vector<string_ptr> &res);
  bool isEmpty(string_ptr value);

  string_ptr toUpper(string_ptr str);
  string_ptr toLower(string_ptr str);
  std::wstring toLower(std::wstring str);
  string_ptr replaceAll(const string_ptr str, const string_ptr oldStr, const string_ptr newStr);

  string_ptr Trim(const string_ptr str);

  std::string charToString(char c);

  // trim from start
  std::string ltrim(std::string &s);
  // trim from end
  std::string rtrim(std::string &s);
  // trim from both ends
  std::string trim(std::string &s);

  // trim from start
  std::wstring ltrim(std::wstring &s);
  // trim from end
  std::wstring rtrim(std::wstring &s);
  // trim from both ends
  std::wstring trim(std::wstring &s);

  // 删除 /* */ 之间的注释，变为空格
  std::string deleteComment(std::string str);
};
